/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package net.huangp.domain;

import java.io.Serializable;
import java.util.Date;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.PrePersist;
import javax.persistence.Table;
import javax.persistence.Temporal;
import org.hibernate.annotations.Generated;
import org.hibernate.annotations.GenerationTime;

/**
 *
 * @author Patrick Huang
 */
@Entity
@Table(name="error_log")
public class ErrorLog implements Serializable{
    //--------------------------------------------------------------------------
    // Static Properties
    //--------------------------------------------------------------------------

    //--------------------------------------------------------------------------
    // Properties
    //--------------------------------------------------------------------------
    @Id
    @Column(name="error_id")
    @GeneratedValue(strategy=GenerationType.AUTO)
    private Long id;

    @Column
    private String error;

    @Column(name="error_detail",length=1024)
    private String errorDetail;

    @Column(name="error_time",updatable=false)
    @Temporal(javax.persistence.TemporalType.TIMESTAMP)
    private Date errorTime = new Date();

    // -------------------------------------------------------------------------
    // Implementation Methods
    // -------------------------------------------------------------------------
    /**
     * will not fire if using session rather than EntityManager
     */
    @PrePersist
    public void setErrorTime(){
        errorTime = new Date();
    }

    public ErrorLog(){
        super();
    }

    public ErrorLog(String error,String errorDetail){
        super();
        this.error = error;
        this.errorDetail = errorDetail;
    }

    @Override
    public boolean equals(Object obj) {
        if (obj == null) {
            return false;
        }
        if (getClass() != obj.getClass()) {
            return false;
        }
        final ErrorLog other = (ErrorLog) obj;
        if ((this.errorDetail == null) ? (other.errorDetail != null) : !this.errorDetail.equals(other.errorDetail)) {
            return false;
        }
        return true;
    }

    @Override
    public int hashCode() {
        int hash = 3;
        hash = 97 * hash + (this.errorDetail != null ? this.errorDetail.hashCode() : 0);
        return hash;
    }

    @Override
    public String toString() {
        StringBuilder sb = new StringBuilder("ErrorLog:[");
        sb.append("id:[").append(id==null?"":id).append("],\n")
            .append("error:[").append(error).append("],\n")
            .append("errorDetail:[").append(errorDetail).append("],\n")
            .append("errorTime:[").append(errorTime==null?"":errorTime).append("],\n")
                ;
        return sb.toString();
    }


    // -------------------------------------------------------------------------
    // Mutator Methods
    // -------------------------------------------------------------------------
    public String getError() {
        return error;
    }

    public void setError(String error) {
        this.error = error;
    }

    public String getErrorDetail() {
        return errorDetail;
    }

    public void setErrorDetail(String errorDetail) {
        this.errorDetail = errorDetail;
    }

    public Date getErrorTime() {
        return errorTime;
    }

    public void setErrorTime(Date errorTime) {
        this.errorTime = errorTime;
    }

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }
}
